import 'package:flutter/material.dart';
import 'package:sow_app/view/home/info/login/become_author_page.dart';
import 'package:sow_app/view/home/info/login/change_password_page.dart';
import 'package:sow_app/view/home/info/login/feedback_page.dart';
import 'package:sow_app/view/home/info/personal_info.dart';

import 'package:sow_app_core/sow_app_core.dart';
import 'package:sow_app_i18n/sow_app_i18n.dart';

import '../../../presenter/state_info_presenter.dart';
import 'login/login_page.dart';
import 'setting/setting_page.dart';

class InfoPage extends StatefulWidget implements AppPage {
  static const routeName = '/info';

  final StateInfoPresenter presenter;
  final InfoController controller;
  const InfoPage({Key? key, required this.presenter, required this.controller})
      : super(key: key);

  @override
  State<InfoPage> createState() => _InfoPageState();
}

class _InfoPageState extends State<InfoPage> {
  @override
  void initState() {
    widget.presenter.presenterContext = context;
    widget.presenter.presenterSetState = setState;
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: false,
        title: const Text(I18n.info),
        actions: [
          IconButton(
              onPressed: () {
                Navigator.pushNamed(context, SettingPage.routeName);
              },
              icon: const Icon(Icons.settings)),
        ],
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Padding(
            padding: const EdgeInsets.only(left: 8.0, top: 8.0),
            child: Text(
              '${I18n.welcome}，${widget.presenter.user.nickName}',
              style: Theme.of(context).textTheme.headline4,
            ),
          ),
          const Spacer(),
          Column(
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  TextButton(
                    onPressed: () {},
                    child: Column(children: [
                      Text(
                        widget.presenter.user.balance!,
                        style: Theme.of(context).textTheme.bodyMedium,
                      ),
                      Text(
                        I18n.balance,
                        style: Theme.of(context).textTheme.bodySmall,
                      ),
                    ]),
                  ),
                  TextButton(
                    onPressed: () {},
                    child: Text(
                      I18n.withdrawals_exchange,
                      style: Theme.of(context).textTheme.bodyMedium,
                    ),
                  ),
                  TextButton(
                    onPressed: () {},
                    child: Text(
                      I18n.invite_friend,
                      style: Theme.of(context).textTheme.bodyMedium,
                    ),
                  ),
                ],
              ),
            ],
          ),
          const Spacer(),
          Padding(
            padding: const EdgeInsets.only(left: 8.0),
            child: Text(
              I18n.normal_tool,
              style: Theme.of(context).textTheme.headline5,
            ),
          ),
          Column(
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  TextButton(
                    onPressed: () {},
                    child: Text(
                      I18n.browse_history,
                      style: Theme.of(context).textTheme.bodyMedium,
                    ),
                  ),
                  TextButton(
                    onPressed: () {},
                    child: Text(
                      I18n.my_message,
                      style: Theme.of(context).textTheme.bodyMedium,
                    ),
                  ),
                  TextButton(
                    onPressed: () {},
                    child: Text(
                      I18n.my_attention,
                      style: Theme.of(context).textTheme.bodyMedium,
                    ),
                  ),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  TextButton(
                    onPressed: () {},
                    child: Text(
                      I18n.reading_preference,
                      style: Theme.of(context).textTheme.bodyMedium,
                    ),
                  ),
                  TextButton(
                    onPressed: () {
                      Navigator.pushNamed(context, BecomeAuthorPage.routeName);
                    },
                    child: Text(
                      I18n.become_author,
                      style: Theme.of(context).textTheme.bodyMedium,
                    ),
                  ),
                  TextButton(
                    onPressed: () {
                      Navigator.pushNamed(context, FeedbackPage.routeName);
                    },
                    child: Text(
                      I18n.feedback_and_help,
                      style: Theme.of(context).textTheme.bodyMedium,
                    ),
                  ),
                ],
              ),
            ],
          ),
          const Spacer(),
          Padding(
            padding: const EdgeInsets.only(left: 8.0),
            child: Text(
              I18n.my_account,
              style: Theme.of(context).textTheme.headline5,
            ),
          ),
          Column(
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  TextButton(
                    onPressed: () {
                      Navigator.pushNamed(context, PersonalInfoPage.routeName);
                    },
                    child: Text(
                      I18n.more_info,
                      style: Theme.of(context).textTheme.bodyMedium,
                    ),
                  ),
                  TextButton(
                    onPressed: () {
                      Navigator.pushNamed(
                          context, ChangePasswordPage.routeName);
                    },
                    child: Text(
                      I18n.change_password,
                      style: Theme.of(context).textTheme.bodyMedium,
                    ),
                  ),
                  TextButton(
                    onPressed: () async {
                      await Navigator.pushNamed(context, LoginPage.routeName);
                    },
                    child: Text(
                      I18n.logout,
                      style: Theme.of(context).textTheme.bodyMedium,
                    ),
                  ),
                ],
              ),
            ],
          ),
          Center(
            child: Icon(
              Icons.book,
              color: Colors.grey.shade300,
              size: 120,
            ),
          ),
          const Spacer(),
        ],
      ),
    );
  }
}
